﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using SVC.client;
namespace UI.Forms
{
    public partial class whd_M : FormBase1
    {
        private BindingList<View_Emp_lite> emps;
        private BindingList<View_whd_d_0> whd_ds;
        public whd_M()
        {
            InitializeComponent();
        }

        private void btn_Import_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            外乎单数据导入 frm = new 外乎单数据导入();
            frm.FatherRefresh = import;
            frm.ShowDialog();
        }

        private void whd_M_Load(object sender, EventArgs e)
        {
            whd_ds = new BindingList<View_whd_d_0>();
            emps=my.bw.View_Emp_lite_List("", my.ACID);
            lue_op.Properties.DataSource = emps;
            lue_op.EditValue = my.emp_lite.EmplID;
            lue_d.Properties.DataSource = emps;
            dateEdit1.EditValueChanged += new EventHandler(dateEdit1_EditValueChanged);
            te_pid.Properties.ReadOnly = true;
            dateEdit1.DateTime = DateTime.Now;
            gc_whd.DataSource = whd_ds;
        }
        private void import(BindingList<View_whd_d_0> whds)
        {
            whd_ds.Clear();
            foreach (View_whd_d_0 item in whds)
            {
                whd_ds.Add(item);
            }
        }

        void dateEdit1_EditValueChanged(object sender, EventArgs e)
        {
            te_pid.Text = my.bw.getBillNO(my.emp_lite.shopcode, dateEdit1.DateTime, 8, my.ACID);
        }

        private void btn_OK_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (!dvp_m.Validate()) return;
	        SVC.client.whd_M m = new SVC.client.whd_M();
            m.info_OPid = new Guid(lue_d.EditValue.ToString());
            m.Pdate = dateEdit1.DateTime;
            m.pid = te_pid.Text;
            m.TS_EmplID = new Guid(lue_op.EditValue.ToString());
            string r = my.bw.whd_add(m, gc_whd.DataSource as BindingList<View_whd_d_0>, my.ACID);
            if (!string.IsNullOrWhiteSpace(r))
            {
                Comm.ShowErorr(r);
            }
            else
            {
                Comm.ShowInfo("单据保存成功！");
                this.Close();
            }
        }
    }
}